//
//  YJCollectionViewCell.m
//  练习
//
//  Created by hcios on 2017/7/5.
//  Copyright © 2017年 hcios. All rights reserved.
//

#import "YJCollectionViewCell.h"
#import "UIImageView+WebCache.h"

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_Height [UIScreen mainScreen].bounds.size.height
#define FONT_NAME_LIH @"FZLanTingHeiS-R-GB"

@implementation YJCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setupSubViews];
    }
    return self;
}


-(void)setupSubViews{
    
    //背景图片
    _bgImageView = [[UIImageView alloc] initWithFrame:self.bounds];
    _bgImageView.userInteractionEnabled = YES;
    _bgImageView.layer.cornerRadius = 4;
    _bgImageView.layer.masksToBounds = YES;
//    _bgImageView.backgroundColor = [UIColor redColor];
    [self addSubview:_bgImageView];
    
    //标题
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, SCREEN_WIDTH, 30)];
    [_titleLabel setTextColor:[UIColor whiteColor]];
    [_titleLabel setFont:[UIFont fontWithName:FONT_NAME_LIH size:18]];
    
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    _titleLabel.tintColor = [UIColor whiteColor];
    _titleLabel.shadowColor = [UIColor grayColor];
    _titleLabel.shadowOffset = CGSizeMake(1, 1);
    [_bgImageView addSubview:_titleLabel];
    
    //副标题
    _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(_titleLabel.frame) + 5, SCREEN_WIDTH, 20)];
    [_contentLabel setTextColor:[UIColor whiteColor]];
    [_contentLabel setFont:[UIFont fontWithName:FONT_NAME_LIH size:13]];
    _contentLabel.textAlignment = NSTextAlignmentLeft;
    _contentLabel.shadowColor = [UIColor grayColor];
    _contentLabel.shadowOffset = CGSizeMake(1, 1);
    [_bgImageView addSubview:_contentLabel];
    
    //头像button
    _imageViewBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _imageViewBtn.frame = CGRectMake(15, self.frame.size.height - 50, 40, 40);
    _imageViewBtn.layer.cornerRadius = 20;
    _imageViewBtn.layer.masksToBounds = YES;
    _imageViewBtn.layer.borderWidth = 2;
    _imageViewBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [_imageViewBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [_bgImageView addSubview:_imageViewBtn];
 
    //作者图片
    _authorImageView = [[UIImageView alloc] initWithFrame:_imageViewBtn.bounds];
    _authorImageView.layer.cornerRadius = 20;
    _authorImageView.layer.masksToBounds = YES;
    _authorImageView.layer.borderWidth = 2;
    _authorImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    [_imageViewBtn addSubview:_authorImageView];
    
    
}

-(void)click:(id)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(gesAuthor:)]) {
        [self.delegate gesAuthor:sender];
    }
}



-(void)setModel:(YJModel *)model{
    _model = model;
    
    [_bgImageView sd_setImageWithURL:[NSURL URLWithString:model.yj_front_cover_photo_url] placeholderImage:[UIImage imageNamed:@"zhanWeiTu"]];
    [_authorImageView sd_setImageWithURL:[NSURL URLWithString:model.user_image_url] placeholderImage:[UIImage imageNamed:@"头像占位图"]];
    _titleLabel.text = model.yj_name;
    _contentLabel.text = [NSString stringWithFormat:@"%@ /%@天 /%@图",model.yj_start_date,model.yj_days,model.yj_photos_count];
}


-(void)modelWithDict:(NSDictionary *)dict{
    [_bgImageView sd_setImageWithURL:[NSURL URLWithString:dict[@"front_cover_photo_url"]] placeholderImage:[UIImage imageNamed:@"zhanWeiTu"]];
    [_authorImageView sd_setImageWithURL:[NSURL URLWithString:dict[@"user"][@"user_img"]] placeholderImage:[UIImage imageNamed:@"头像占位图"]];
    _titleLabel.text = dict[@"name"];
    _contentLabel.text = [NSString stringWithFormat:@"%@ /%@天 /%@图",dict[@"start_day"],dict[@"day"],dict[@"photo_count"]];
}

@end
